﻿using System;
using System.Linq;
using log4net;
using Metozis.Data;
using Metozis.Model;

namespace Metozis.Repo
{
    internal class ReceipientInvoiceRepo : IReceipientInvoiceRepo
    {
       private Db db;
        private ILog log;

       public ReceipientInvoiceRepo(ILog log, Db db)
       {
           this.log = log;
            this.db = db;
        }

        public ReceipientInvoice GetInvoiceById(int id)
        {
            log.InfoFormat("Metozis.Repo.ReceipientInvoiceRepo.GetInvoiceById({0})", id);
            try
            {
                return db.GetInvoices().First(item => item.Id == id);
            }
            catch (Exception caught)
            {
                log.Error(caught.Message);
                throw new ApplicationException(caught.Message, caught);
            }
        }
    }
}